﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace NNote {
	public partial class NNoteTextBox : UserControl, NNote.ITextBox {
		public NNoteTextBox() {
			InitializeComponent();
		}

		public bool Modified {
			get { return inner.Modified; }
			set { inner.Modified = value; }
		}

		public event EventHandler ModifiedChanged {
			add { inner.ModifiedChanged += value; }
			remove { inner.ModifiedChanged -= value; }
		}

		#region FileCommands
		public void NewFile() {
			FilePath = null;
			FileTitle = "Untitled";
			inner.Clear();
			Modified = false;
		}
		public void LoadFile(string filePath) {
			FilePath = filePath;
			FileTitle = Path.GetFileName(filePath);
			inner.LoadFile(filePath, RichTextBoxStreamType.PlainText);
			Modified = false;
		}
		public void SaveFile(string filePath) {
			FilePath = filePath;
			FileTitle = Path.GetFileName(filePath);
			inner.SaveFile(filePath, RichTextBoxStreamType.PlainText);
			Modified = false;
		}
		#endregion

		#region Edit Commands

		public void Cut() {
			inner.Cut();
		}
		public void Copy() {
			inner.Copy();
		}
		public void Paste() {
			var format = DataFormats.GetFormat(DataFormats.UnicodeText);
			inner.Paste(format);
		}

		public void SelectAll() {
			inner.SelectAll();
		}

		#endregion

		public string FilePath { get; private set; }
		public string FileTitle { get; private set; }

		public override string Text {
			get { return inner.Text; }
			set { inner.Text = value; }
		}
		public override Font Font {
			get { return base.Font; }
			set { base.Font = inner.Font = value; }
		}
		public override Color BackColor {
			get { return inner.BackColor; }
			set { base.BackColor = inner.BackColor = value; }
		}
		public override Color ForeColor {
			get { return base.ForeColor; }
			set { base.ForeColor = inner.ForeColor = value; }
		}

		public bool WordWrap {
			get { return inner.WordWrap; }
			set { inner.WordWrap = value; }
		}
	}
}
